/*
 * @Author: szx
 * @Date: 2022-04-01 13:45:20
 * @LastEditTime: 2022-04-01 13:52:11
 * @Description:
 * @FilePath: \leetcode\500-599\567\567.js
 */
/**
 * @param {string} s1
 * @param {string} s2
 * @return {boolean}
 */
var checkInclusion = function (s1, s2) {
    const m = s1.length,
        n = s2.length;
    if (m > n) return false;
    const arr = new Array(26).fill(0);
    for (let i of s1) {
        arr[i.charCodeAt() - 97]--;
    }
    let l = 0;
    for (let r = 0; r < n; i++) {
        const x = s2[r].charCodeAt() - 97;
        arr[x]++;
        while (arr[x] > 0) {
            arr[s2[l].charCodeAt() - 97]--;
            l++;
        }
        if (r - l + 1 == m) return true;
    }
    return false;
};
